package cn.arnold.leetcode;

import java.util.Scanner;

/**
 * @Author Arnold
 * @Desc 字符串数组最长公共前缀
 **/
public class LongestCommonPrefix {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String s = scanner.nextLine();
        String[] strs = s.split(",");
        System.out.println(func(strs));
    }

    public static String func(String[] strs) {
        //两两比较，两两比较后的值依次与之后的比较
        if (strs.length == 0) {
            return ""; //没有返回""
        }
        String ans = strs[0];
        for (int i = 1; i < strs.length; i++) {
            int j = 0;
            while (j < ans.length() && j < strs[i].length()) {
                if (ans.charAt(j) == strs[i].charAt(j)) {
                    j++;
                } else {
                    break;
                }
            }
            ans = ans.substring(0, j);
            if (ans.equals("")) {
                return ans;
            }
        }
        return ans;
    }
}
